package com.rcp.steve.crm.util;

import java.sql.*;

public class DBAssistant {
    public DBAssistant() {
    }

    public static void closeRS(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
                rs = null;
            } catch (Exception e) {

            }
        }
    }

    public static void closeStatement(Statement pre) {
        if (pre != null) {
            try {
                pre.close();
                pre = null;
            } catch (Exception e) {

            }
        }
    }
    public static void closePreparedStatement(PreparedStatement pre) {
   if (pre != null) {
     try {
       pre.close();
       pre = null;
     }
     catch (Exception e) {

     }
   }
 }


    public static void closeConn(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
                conn = null;
            } catch (Exception e) {

            }
        }
    }

    public static void closeConn2(Connection conn) {
        if (conn != null) {
            try {
                conn.rollback();
                conn.setAutoCommit(true);
                conn.close();
                conn = null;
            } catch (Exception e) {

            }
        }
    }

    public static void closePreparedStatment(PreparedStatement pstm) {
        if (pstm != null) {
            try {
                pstm.close();
                pstm = null;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    public static void closeRSC(ResultSet rs, Statement pre, Connection conn) {
        closeRS(rs);
        closeStatement(pre);
        closeConn(conn);
    }
    public static void closeRSC(ResultSet rs, PreparedStatement pre, Connection conn) {
        closeRS(rs);
        closePreparedStatement(pre);
        closeConn(conn);
    }

}
